unit uSelectUser;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxContainer, cxEdit, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, cxStyles, dxSkinscxPCPainter, cxCustomData, cxFilter,
  cxData, cxDataStorage, cxNavigator, Data.DB, cxDBData, cxTextEdit, cxCheckBox,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxGridCustomView, cxGrid, Datasnap.DBClient, ClientRowSet,
  cxGroupBox, Vcl.Menus, Vcl.StdCtrls, cxButtons, cxDBLookupComboBox,
  cxImageComboBox;

type
  TFrmSelectUser = class(TForm)
    cxGroupBox1: TcxGroupBox;
    crsUser: TClientRowSet;
    crsUserUSER_ID: TStringField;
    crsUserUSER_NO: TStringField;
    crsUserUSER_NAME: TStringField;
    crsUserUSR_TYPE: TStringField;
    crsUserACTOR_ID: TStringField;
    crsUserACTOR_NAME: TStringField;
    crsUserACTOR_IDS: TStringField;
    crsUserPASSWORD: TStringField;
    crsUserSYS_ACCOUNT: TStringField;
    crsUserGROUP_CODE: TStringField;
    crsUserCOMPANY: TStringField;
    crsUserNODE_ID: TStringField;
    crsUserNODE_NO: TStringField;
    crsUserNODE_NAME: TStringField;
    crsUserREGDATE: TStringField;
    crsUserLOGIN_DATETIME: TStringField;
    crsUserUPDATETIME: TStringField;
    crsUserEFFECTIVE_DATE: TStringField;
    crsUserIS_LOGIN: TSmallintField;
    crsUserSTATUS: TIntegerField;
    crsUserDISABLED: TIntegerField;
    crsUserEMP_NO: TStringField;
    crsUserWORK_NO: TIntegerField;
    crsUserDEPART: TStringField;
    crsUserCUST_SCOPE: TStringField;
    crsUserCITY: TStringField;
    crsUserADDRESS: TStringField;
    crsUserPOST_CODE: TStringField;
    crsUserMOBILE: TStringField;
    crsUserTEL_HEAD: TStringField;
    crsUserTEL: TStringField;
    crsUserSUB_TEL: TStringField;
    crsUserEMAIL: TStringField;
    crsUserPHONE_TYPE: TStringField;
    crsUserHOST_ADDRESS: TStringField;
    crsUserREMARK: TStringField;
    crsUserVERSION: TIntegerField;
    crsUserWX_ID: TStringField;
    crsUserCARD_NO: TStringField;
    crsUserCHANEL_ID: TStringField;
    crsUserLANGUAGE: TStringField;
    crsUserSOURCE: TSmallintField;
    crsUserFEE_ACCNO: TStringField;
    crsUserDEVICE_ID: TStringField;
    dsUser: TDataSource;
    crsUserIsCheck: TBooleanField;
    Label2: TLabel;
    edtEmpNo: TcxTextEdit;
    cxButton2: TcxButton;
    cxButton1: TcxButton;
    btAll: TcxButton;
    crsUserDUTY: TStringField;
    GrdBasic: TcxGrid;
    tvUsers: TcxGridDBTableView;
    lvEXP_COMP: TcxGridLevel;
    tvUsersDUTY: TcxGridDBColumn;
    tvUsersIsCheck: TcxGridDBColumn;
    tvUsersUSER_NO: TcxGridDBColumn;
    tvUsersUSER_NAME: TcxGridDBColumn;
    tvUsersMOBILE: TcxGridDBColumn;
    tvUsersNODE_NO: TcxGridDBColumn;
    tvUsersNODE_NAME: TcxGridDBColumn;
    tvUsersUSER_ID: TcxGridDBColumn;
    cxButton3: TcxButton;
    procedure cxButton2Click(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure btAllClick(Sender: TObject);
    procedure tvUsersCustomDrawIndicatorCell(Sender: TcxGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo;
      var ADone: Boolean);
    procedure FormCreate(Sender: TObject);
  private
    Notice_ID:string;
    UserList:TStringList;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmSelectUser: TFrmSelectUser;
  procedure FrmSelectUserShow(ID:string;var sList:TStringList);

implementation

{$R *.dfm}

uses ucommFunction, Console;

procedure FrmSelectUserShow(ID:string;var sList:TStringList);
begin
  Application.CreateForm(TFrmSelectUser,FrmSelectUser);
  with FrmSelectUser do
  try
    UserList:=TStringList.Create;
    Notice_ID:=ID;
    cxButton2.Click;
    if ShowModal=mrOK then
      sList.Assign(UserList);
  finally
    UserList.Free;
    FreeAndNil(FrmSelectUser);
  end;
end;

procedure TFrmSelectUser.cxButton1Click(Sender: TObject);
var
  I,Col,iValue:Integer;
begin
   col:=tvUsers.DataController.GetItemByFieldName('IsCheck').Index;
   iValue:=tvUsers.DataController.GetItemByFieldName('USER_ID').Index;
   for I := 0 to tvUsers.DataController.RecordCount-1 do
   begin
     if tvUsers.DataController.Values[I,Col]=True then
       UserList.Add(tvUsers.DataController.Values[I,iValue]);
   end;
   Self.ModalResult:=mrOk;
end;

procedure TFrmSelectUser.cxButton2Click(Sender: TObject);
var
  SQLText: string;
begin
  SQLText := 'SELECT a.*,b.duty FROM sys_user a left join bas_employee b on a.emp_no=b.emp_no WHERE a.group_code=' + QuotedStr(userInfo.groupCode)+' and b.STATE=0';
  SQLText:=SQLText+' and a.user_id not in (select user_id from tsp_notice_detail where notice_id='+QuotedStr(Notice_ID)+')';
  SQLText:=SQLText+' and nvl(FEE_ACCNO,''0000'')=''0000''';
  if Trim(edtEmpNo.Text) <> '' then
    SQLText := SQLText + ' AND (a.user_no LIKE ' + QuotedStr('%' + edtEmpNo.Text + '%') + ' OR ' + ' a.user_name LIKE ' + QuotedStr('%' + edtEmpNo.Text + '%') + ' OR ' + ' mobile like ' + QuotedStr('%' + edtEmpNo.Text + '%') + ')';
  if not userInfo.isCenter then
    SQLText:=SQLText+' and a.Node_no in '+userInfo.NodeStr;
  SQLText := SQLText + ' ORDER BY a.user_no';
  crsUser.Close;
  crsUser.CommandText := SQLText;
  crsUser.Open;
end;

procedure TFrmSelectUser.FormCreate(Sender: TObject);
begin
  pSetCaption(Self);
end;

procedure TFrmSelectUser.btAllClick(Sender: TObject);
var
  i,col:integer;
begin
  col:=tvUsers.DataController.GetItemByFieldName('IsCheck').Index;
  for I :=0  to tvUsers.ViewData.RecordCount-1 do
  begin
    if TcxButton(Sender).Name='btAll' then
      tvUsers.ViewData.Rows[I].Values[col]:=True
    else
      tvUsers.ViewData.Rows[I].Values[col]:=False;
  end;
end;

procedure TFrmSelectUser.tvUsersCustomDrawIndicatorCell(
  Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    FValue :=IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index+1);
    FBounds := AViewInfo.Bounds;
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    InflateRect(FBounds, -1, -1);
    //ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

end.
